package com.bookkeeping.bookkeepingapi.model;

import com.bookkeeping.bookkeepingapi.web.vm.UserVM;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

@Entity
@Table(name="user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Data  //Lombook 省去写get、set
@AllArgsConstructor
@NoArgsConstructor
public class User implements Serializable {

    @Id
    //主键自增
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;//主键

    @Column(name = "add_time")
    private LocalDateTime addTime=LocalDateTime.now();

    @Column(name = "update_time")
    private LocalDateTime updateTime=LocalDateTime.now();

    @Column
    private String username;

    private String realname;

    @Column
    private String password;

    @Column
    private Integer count=0;

    public User(UserVM userVM)
    {
        this.username=userVM.getUsername();
        this.realname=userVM.getRealname();
    }

}

